package com.sun.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebFilter(urlPatterns = "*")
public class EncodingFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        String font = "text/html;charset=UTF-8";
        response.setContentType(font);
        System.out.println("字符编码过滤器:"+font);
        filterChain.doFilter(servletRequest, servletResponse);
    }
}